import { useEffect } from "react";
import { connect } from "react-redux";
import { timeincrement } from "../store/actions/time";

function Time(props) {
    const { time, timeincrement } = props;
    useEffect(() => {
        const timer = setInterval(() => {
            timeincrement();
        }, 1000);
        return () => {
            clearInterval(timer);
        };
    }, []);
    return (
        <>
            <div className='alert alert-warning'>当前时间为：{time}</div>
        </>
    );
}

const mapState = (state) => {
    return {
        time: state.time.time,
    };
};

export default connect(mapState, { timeincrement })(Time);
